﻿using QxFramework.Core;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;

public class ButtonClick : MonoBehaviour, IPointerClickHandler
{

    public UnityEvent leftClick;
    public UnityEvent middleClick;
    public UnityEvent rightClick;
    Chess chess;
    private void Start()
    {
        leftClick.AddListener(new UnityAction(ButtonLeftClick));
        middleClick.AddListener(new UnityAction(ButtonMiddleClick));
        rightClick.AddListener(new UnityAction(ButtonRightClick));
        chess= this.transform.GetComponent<Chess>();
    }


    public void OnPointerClick(PointerEventData eventData)
    {
        if (eventData.button == PointerEventData.InputButton.Left)
            leftClick.Invoke();
        else if (eventData.button == PointerEventData.InputButton.Middle)
            middleClick.Invoke();
        else if (eventData.button == PointerEventData.InputButton.Right)
            rightClick.Invoke();
    }


    private void ButtonLeftClick()
    {
        if (!chess.player.Movable) return;
        AudioManager.Instance.PlayEffectAudio("ChooseChess", 0.5f);
        chess.player.playerState = PlayerState.HaveChooseChess;
        chess.player.CurChoose = chess.Id;
        chess.player.ClearHighLight();
        UIManager.Instance.Open("ActionUI", "", this.GetComponent<Chess>());
    }

    private void ButtonMiddleClick()
    {
    }

    private void ButtonRightClick()
    {
    }
}

